package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.CategoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/category")
@Slf4j
@RestController
@Api(tags = "分类操作接口")
public class CategoryController {
    @Autowired
    private CategoryServiceImpl categoryService;

    /**
     * 分类分页查看
     *
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分类和套餐分类接口")
    public Result CategoryPage(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.categoryPage(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 编辑分类信息
     *
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑分类")
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("设置分类起售状态")
    public Result setStatus(@PathVariable String status, String id) {
        categoryService.setStatus(status, id);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("添加分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("删除分类")
    public Result deleteCategory(String id) {
        categoryService.deleCategory(id);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据类型查找分类")
    public Result<List<Category>> selectById(String type){

        List<Category> select = categoryService.select(type);
        return Result.success(select);
    }

}
